]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
systemActions: Make actions searchable
authorRares Visalom <rares.visalom@gmail.com>
Wed, 2 Aug 2017 22:21:17 +0000 (01:21 +0300)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 22 Aug 2017 10:42:32 +0000 (12:42 +0200)
Every action has specific associated terms that
identify that action and show it in the search
results. Methods to match the actions as well
as getting properties of specific actions are
needed in order to provide a way of using the
actions.

https://bugzilla.gnome.org/show_bug.cgi?id=691900

js/misc/systemActions.js
po/POTFILES.in

index f0fdede35f6575eaa9f31af2c732eafd5743bffa..778c0eaf786ebb388252f481bbcc25d8cb90719f 100644 (file)
@@ -95,17 +95,46 @@ const SystemActions = new Lang.Class({
 
         this._actions = new Map();
         this._actions.set(POWER_OFF_ACTION_ID,
-                          { available: false });
+                          { // Translators: The name of the power-off action in search
+                            name: C_("search-result", "Power off"),
+                            iconName: 'system-shutdown-symbolic',
+                            // Translators: A list of keywords that match the power-off action, separated by semicolons
+                            keywords: _("power off;shutdown").split(';'),
+                            available: false });
         this._actions.set(LOCK_SCREEN_ACTION_ID,
-                          { available: false });
+                          { // Translators: The name of the lock screen action in search
+                            name: C_("search-result", "Lock screen"),
+                            iconName: 'system-lock-screen-symbolic',
+                            // Translators: A list of keywords that match the lock screen action, separated by semicolons
+                            keywords: _("lock screen").split(';'),
+                            available: false });
         this._actions.set(LOGOUT_ACTION_ID,
-                          { available: false });
+                          { // Translators: The name of the logout action in search
+                            name: C_("search-result", "Log out"),
+                            iconName: 'application-exit-symbolic',
+                            // Translators: A list of keywords that match the logout action, separated by semicolons
+                            keywords: _("logout;sign off").split(';'),
+                            available: false });
         this._actions.set(SUSPEND_ACTION_ID,
-                          { available: false });
+                          { // Translators: The name of the suspend action in search
+                            name: C_("search-result", "Suspend"),
+                            iconName: 'media-playback-pause-symbolic',
+                            // Translators: A list of keywords that match the suspend action, separated by semicolons
+                            keywords: _("suspend;sleep").split(';'),
+                            available: false });
         this._actions.set(SWITCH_USER_ACTION_ID,
-                          { available: false });
+                          { // Translators: The name of the switch user action in search
+                            name: C_("search-result", "Switch user"),
+                            iconName: 'system-switch-user-symbolic',
+                            // Translators: A list of keywords that match the switch user action, separated by semicolons
+                            keywords: _("switch user").split(';'),
+                            available: false });
         this._actions.set(LOCK_ORIENTATION_ACTION_ID,
-                          { iconName: '',
+                          { // Translators: The name of the lock orientation action in search
+                            name: C_("search-result", "Lock orientation"),
+                            iconName: '',
+                            // Translators: A list of keywords that match the lock orientation action, separated by semicolons
+                            keywords: _("lock orientation").split(';'),
                             available: false });
 
         this._loginScreenSettings = new Gio.Settings({ schema_id: LOGIN_SCREEN_SCHEMA });
@@ -237,6 +266,50 @@ const SystemActions = new Lang.Class({
         this._updateHaveSuspend();
     },
 
+    getMatchingActions: function(terms) {
+        // terms is a list of strings
+        terms = terms.map((term) => { return term.toLowerCase(); });
+
+        let results = [];
+
+        for (let [key, {available, keywords}] of this._actions)
+            if (available && terms.every(t => keywords.some(k => (k.indexOf(t) >= 0))))
+                results.push(key);
+
+        return results;
+    },
+
+    getName: function(id) {
+        return this._actions.get(id).name;
+    },
+
+    getIconName: function(id) {
+        return this._actions.get(id).iconName;
+    },
+
+    activateAction: function(id) {
+        switch (id) {
+            case POWER_OFF_ACTION_ID:
+                this.activatePowerOff();
+                break;
+            case LOCK_SCREEN_ACTION_ID:
+                this.activateLockScreen();
+                break;
+            case LOGOUT_ACTION_ID:
+                this.activateLogout();
+                break;
+            case SUSPEND_ACTION_ID:
+                this.activateSuspend();
+                break;
+            case SWITCH_USER_ACTION_ID:
+                this.activateSwitchUser();
+                break;
+            case LOCK_ORIENTATION_ACTION_ID:
+                this.activateLockOrientation();
+                break;
+        }
+    },
+
     _updateLockScreen() {
         let showLock = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
         let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
index fe31315b78b6eaa957b546c50303b9a95c1e3a9c..03ff3a552caab9998562dc2254cb6cff1dae8d7f 100644 (file)
@@ -9,6 +9,7 @@ js/extensionPrefs/main.js
 js/gdm/authPrompt.js
 js/gdm/loginDialog.js
 js/gdm/util.js
+js/misc/systemActions.js
 js/misc/util.js
 js/portalHelper/main.js
 js/ui/accessDialog.js